# 导包
import pytest
import requests
from config import *


# 定义测试类
class TestLogin:
    # 前置方法

    def setup_method(self):
        response = requests.get(f"{BASE_URL}/api/captchaImage")
        self.uuid = response.json()["uuid"]

    # case01: 登录成功
    @pytest.mark.parametrize("username, password, status_code, message", read_json('login.json'))
    def test_login_success(self, username, password, status_code, message):
        login_data = {
            "username": username,
            "password": password,
            "code": "2",
            "uuid": self.uuid
        }
        response = requests.post(url=f"{BASE_URL}/api/login", json=login_data)
        print(response.json())
        # 断言
        assert response.status_code == 200
        assert response.json().get("code") == status_code
        assert message in response.text
